/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.gac.gacmod.core;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.sql.Wrapper;
import javax.swing.Action;
import org.gac.gacmod.palette.StepCategoryChildren;
import org.gac.gacmod.stepmanager.StepTypeWrapper;
import org.netbeans.spi.palette.DragAndDropHandler;
import org.netbeans.spi.palette.PaletteActions;
import org.netbeans.spi.palette.PaletteController;
import org.netbeans.spi.palette.PaletteFactory;
import org.openide.nodes.AbstractNode;
import org.openide.util.Lookup;
import org.openide.util.datatransfer.ExTransferable;

/**
 *
 * @author Tomek
 */
public class StepPaletteHelper {
public static PaletteController createPalette() {
        AbstractNode paletteRoot = new AbstractNode(new StepCategoryChildren());
        paletteRoot.setName("Palette Root");
        return PaletteFactory.createPalette( paletteRoot, new MyActions(), null, new MyDnDHandler() );
    }

    private static class MyActions extends PaletteActions {
        public Action[] getImportActions() {
            return null;
        }

        public Action[] getCustomPaletteActions() {
            return null;
        }

        public Action[] getCustomCategoryActions(Lookup lookup) {
            return null;
        }

        public Action[] getCustomItemActions(Lookup lookup) {
            return null;
        }

        public Action getPreferredAction(Lookup lookup) {
            return null;
        }

    }

    private static class MyDnDHandler extends DragAndDropHandler {

        public void customize(ExTransferable exTransferable, Lookup lookup) {
            final StepTypeWrapper wrapper = lookup.lookup(StepTypeWrapper.class);


            exTransferable.put( new ExTransferable.Single( new DataFlavor( StepTypeWrapper.class,"StepTypeWrapper"))
            {

                @Override
                protected Object getData() throws IOException, UnsupportedFlavorException
                {
                    return wrapper;
                }

            });
//            exTransferable.put(new ExTransferable.Single (DataFlavor.) {
//
//                protected Object getData() throws IOException, UnsupportedFlavorException {
//                    return image;
//                }
//
//            });
        }

    }
}
